<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<title>Rule Bookings</title>
<link href="../docs-assets/Breadcrumbs.css" rel="stylesheet" rev="stylesheet" type="text/css">
		<meta name="viewport" content="width=device-width initial-scale=1">
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<meta http-equiv="Content-Language" content="en-gb">

<link href="../docs-assets/Contents.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Progress.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Navigation.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Fonts.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Base.css" rel="stylesheet" rev="stylesheet" type="text/css">
<script>
function togglePopup(material_id) {
  var popup = document.getElementById(material_id);
  popup.classList.toggle("show");
}
</script>

<link href="../docs-assets/Popups.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Colours.css" rel="stylesheet" rev="stylesheet" type="text/css">
		
	</head>
	<body class="commentary-font">
		<nav role="navigation">
		<h1><a href="../index.html"><img src="../docs-assets/Inform.png" height=72> </a></h1>
<ul><li><a href="../index.html">home</a></li>
</ul><h2>Compiler</h2><ul>
<li><a href="../structure.html">structure</a></li>
<li><a href="../inbuildn.html">inbuild</a></li>
<li><a href="../inform7n.html">inform7</a></li>
<li><a href="../intern.html">inter</a></li>
<li><a href="../services.html">services</a></li>
<li><a href="../secrets.html">secrets</a></li>
</ul><h2>Other Tools</h2><ul>
<li><a href="../inblorbn.html">inblorb</a></li>
<li><a href="../inform6.html">inform6</a></li>
<li><a href="../inpolicyn.html">inpolicy</a></li>
</ul><h2>Resources</h2><ul>
<li><a href="../extensions.html">extensions</a></li>
<li><a href="../kits.html">kits</a></li>
</ul><h2>Repository</h2><ul>
<li><a href="https://github.com/ganelson/inform"><img src="../docs-assets/github.png" height=0> github</a></li>
</ul><h2>Related Projects</h2><ul>
<li><a href="https://github.com/ganelson/inweb"><img src="../docs-assets/github.png" height=0> inweb</a></li>
<li><a href="https://github.com/ganelson/intest"><img src="../docs-assets/github.png" height=0> intest</a></li>
</ul>
		</nav>
		<main role="main">
		<!-- Weave of 'Rule Bookings' generated by inweb -->
<div class="breadcrumbs">
    <ul class="crumbs"><li><a href="../index.html">Home</a></li><li><a href="../inform7n.html">Inform7</a></li><li><a href="index.html">assertions</a></li><li><a href="index.html#6">Chapter 6: Rules, Rulebooks and Activities</a></li><li><b>Rule Bookings</b></li></ul></div>
<p class="purpose">Bookings are assignments of rules to rulebooks.</p>

<ul class="toc"><li><a href="6-rb.html#SP1">&#167;1. Introduction</a></li><li><a href="6-rb.html#SP3">&#167;3. Creation</a></li><li><a href="6-rb.html#SP4">&#167;4. Access</a></li><li><a href="6-rb.html#SP5">&#167;5. Placement</a></li><li><a href="6-rb.html#SP7">&#167;7. Specificity of bookings</a></li><li><a href="6-rb.html#SP8">&#167;8. Commentary</a></li></ul><hr class="tocbar">

<p class="commentary firstcommentary"><a id="SP1" class="paragraph-anchor"></a><b>&#167;1. Introduction.</b>Rules are only really of use in rulebooks, but in fact they can belong to
any number of rulebooks. Each placement of a rule in a rulebook is called
a "booking", and results in a <a href="6-rb.html#SP1" class="internal">booking</a> object. These are gathered into
linked lists as <a href="6-bl.html#SP1" class="internal">booking_list</a> objects: see <a href="6-bl.html" class="internal">Booking Lists</a>.
</p>

<p class="commentary">We can think of rule bookings as being looseleaf pages, of which we have an
unlimited supply: any rule can be written on them. They can be bound into
any rulebook at any specified position, but each rulebook divides into three
non-overlapping sections: the first rules, the middle rules, the last rules.
And each <a href="6-rb.html#SP1" class="internal">booking</a> records which of these sections it belongs to.
</p>

<pre class="definitions code-font"><span class="definition-keyword">enum</span> <span class="constant-syntax">MIDDLE_PLACEMENT</span><span class="plain-syntax"> </span><span class="identifier-syntax">from</span><span class="plain-syntax"> </span><span class="constant-syntax">0</span><span class="plain-syntax"> </span><span class="comment-syntax"> most bookings are in this middle section</span>
<span class="definition-keyword">enum</span> <span class="constant-syntax">VERY_FIRST_PLACEMENT</span>
<span class="definition-keyword">enum</span> <span class="constant-syntax">FIRST_PLACEMENT</span>
<span class="definition-keyword">enum</span> <span class="constant-syntax">LAST_PLACEMENT</span>
<span class="definition-keyword">enum</span> <span class="constant-syntax">VERY_LAST_PLACEMENT</span>
</pre>
<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">typedef</span><span class="plain-syntax"> </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="reserved-syntax">booking</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="reserved-syntax">rule</span><span class="plain-syntax"> *</span><span class="identifier-syntax">rule_being_booked</span><span class="plain-syntax">; </span><span class="comment-syntax"> what appears on this page</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">placement</span><span class="plain-syntax">; </span><span class="comment-syntax"> one of the </span><span class="extract"><span class="extract-syntax">*_PLACEMENT</span></span><span class="comment-syntax"> values above</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">place_automatically</span><span class="plain-syntax">; </span><span class="comment-syntax"> should this be inserted automatically?</span>

<span class="plain-syntax">    </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="reserved-syntax">booking_commentary</span><span class="plain-syntax"> </span><span class="identifier-syntax">commentary</span><span class="plain-syntax">; </span><span class="comment-syntax"> used only for indexing and code comments</span>

<span class="plain-syntax">    </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="reserved-syntax">booking</span><span class="plain-syntax"> *</span><span class="identifier-syntax">next_booking</span><span class="plain-syntax">; </span><span class="comment-syntax"> in its booking list</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">CLASS_DEFINITION</span>
<span class="plain-syntax">} </span><span class="reserved-syntax">booking</span><span class="plain-syntax">;</span>
</pre>
<ul class="endnotetexts"><li>The structure booking is accessed in 6/bl and here.</li></ul>
<p class="commentary firstcommentary"><a id="SP2" class="paragraph-anchor"></a><b>&#167;2. </b>Here's a rather arcane notation used in the debugging log:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">RuleBookings::log</span><span class="plain-syntax">(</span><span class="reserved-syntax">booking</span><span class="plain-syntax"> *</span><span class="identifier-syntax">br</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">br</span><span class="plain-syntax"> == </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">) { </span><span class="identifier-syntax">LOG</span><span class="plain-syntax">(</span><span class="string-syntax">"BR:&lt;null-booked-rule&gt;"</span><span class="plain-syntax">); </span><span class="reserved-syntax">return</span><span class="plain-syntax">; }</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">LOG</span><span class="plain-syntax">(</span><span class="string-syntax">"BR%d"</span><span class="plain-syntax">, </span><span class="identifier-syntax">br</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">allocation_id</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">switch</span><span class="plain-syntax"> (</span><span class="identifier-syntax">br</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">placement</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">MIDDLE_PLACEMENT:</span><span class="plain-syntax"> </span><span class="identifier-syntax">LOG</span><span class="plain-syntax">(</span><span class="string-syntax">"m"</span><span class="plain-syntax">); </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">VERY_FIRST_PLACEMENT:</span><span class="plain-syntax"> </span><span class="identifier-syntax">LOG</span><span class="plain-syntax">(</span><span class="string-syntax">"vf"</span><span class="plain-syntax">); </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">FIRST_PLACEMENT:</span><span class="plain-syntax"> </span><span class="identifier-syntax">LOG</span><span class="plain-syntax">(</span><span class="string-syntax">"f"</span><span class="plain-syntax">); </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">LAST_PLACEMENT:</span><span class="plain-syntax"> </span><span class="identifier-syntax">LOG</span><span class="plain-syntax">(</span><span class="string-syntax">"l"</span><span class="plain-syntax">); </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">VERY_LAST_PLACEMENT:</span><span class="plain-syntax"> </span><span class="identifier-syntax">LOG</span><span class="plain-syntax">(</span><span class="string-syntax">"vl"</span><span class="plain-syntax">); </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">default:</span><span class="plain-syntax"> </span><span class="identifier-syntax">LOG</span><span class="plain-syntax">(</span><span class="string-syntax">"?"</span><span class="plain-syntax">); </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><a href="6-rls.html#SP12" class="function-link"><span class="function-syntax">Rules::log</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">br</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">rule_being_booked</span><span class="plain-syntax">);</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP3" class="paragraph-anchor"></a><b>&#167;3. Creation.</b></p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">booking</span><span class="plain-syntax"> *</span><span class="function-syntax">RuleBookings::new</span><button class="popup" onclick="togglePopup('usagePopup1')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup1">Usage of <span class="code-font"><span class="function-syntax">RuleBookings::new</span></span>:<br/>Rule Placement Requests - <a href="3-rpr.html#SP15_1">&#167;15.1</a><br/>Rules - <a href="6-rls.html#SP17">&#167;17</a><br/>Booking Lists - <a href="6-bl.html#SP4">&#167;4</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">rule</span><span class="plain-syntax"> *</span><span class="identifier-syntax">R</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">booking</span><span class="plain-syntax"> *</span><span class="identifier-syntax">br</span><span class="plain-syntax"> = </span><span class="identifier-syntax">CREATE</span><span class="plain-syntax">(</span><span class="reserved-syntax">booking</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">br</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">next_booking</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">br</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">rule_being_booked</span><span class="plain-syntax"> = </span><span class="identifier-syntax">R</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">br</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">placement</span><span class="plain-syntax"> = </span><span class="constant-syntax">MIDDLE_PLACEMENT</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">br</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">place_automatically</span><span class="plain-syntax"> = </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">br</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">commentary</span><span class="plain-syntax"> = </span><a href="6-rb.html#SP8" class="function-link"><span class="function-syntax">RuleBookings::new_commentary</span></a><span class="plain-syntax">();</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">br</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP4" class="paragraph-anchor"></a><b>&#167;4. Access.</b></p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">rule</span><span class="plain-syntax"> *</span><span class="function-syntax">RuleBookings::get_rule</span><button class="popup" onclick="togglePopup('usagePopup2')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup2">Usage of <span class="code-font"><span class="function-syntax">RuleBookings::get_rule</span></span>:<br/>Booking Lists - <a href="6-bl.html#SP5_2">&#167;5.2</a>, <a href="6-bl.html#SP5_3">&#167;5.3</a>, <a href="6-bl.html#SP5_8_1">&#167;5.8.1</a>, <a href="6-bl.html#SP6">&#167;6</a>, <a href="6-bl.html#SP7">&#167;7</a><br/>Rulebooks - <a href="6-rlb.html#SP17">&#167;17</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">booking</span><span class="plain-syntax"> *</span><span class="identifier-syntax">br</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">br</span><span class="plain-syntax"> == </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">br</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">rule_being_booked</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP5" class="paragraph-anchor"></a><b>&#167;5. Placement.</b>When created, a booking is like a piece of looseleaf paper which has not yet
been put into a binder (i.e., into the <a href="6-bl.html#SP1" class="internal">booking_list</a> of a rulebook); the
process of putting it into such a list is called "placement".
</p>

<p class="commentary">Most rules declare a single rulebook to belong to in their definitions:
</p>

<blockquote>
    <p>Before eating something: ...</p>
</blockquote>

<p class="commentary">This nameless rule is to go into the "before eating" rulebook. When Inform
reads this, it creates a booking, but does not immediately place this into
the rulebook; instead, the booking is marked for automatic placement later on.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">RuleBookings::request_automatic_placement</span><button class="popup" onclick="togglePopup('usagePopup3')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup3">Usage of <span class="code-font"><span class="function-syntax">RuleBookings::request_automatic_placement</span></span>:<br/>Rules - <a href="6-rls.html#SP17">&#167;17</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">booking</span><span class="plain-syntax"> *</span><span class="identifier-syntax">br</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">br</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">place_automatically</span><span class="plain-syntax"> = </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP6" class="paragraph-anchor"></a><b>&#167;6. </b>And now it's later on:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">RuleBookings::make_automatic_placements</span><button class="popup" onclick="togglePopup('usagePopup4')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup4">Usage of <span class="code-font"><span class="function-syntax">RuleBookings::make_automatic_placements</span></span>:<br/>Rule Family - <a href="5-rf.html#SP10">&#167;10</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">void</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">booking</span><span class="plain-syntax"> *</span><span class="identifier-syntax">br</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">LOOP_OVER</span><span class="plain-syntax">(</span><span class="identifier-syntax">br</span><span class="plain-syntax">, </span><span class="reserved-syntax">booking</span><span class="plain-syntax">)</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">br</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">place_automatically</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">imperative_defn</span><span class="plain-syntax"> *</span><span class="identifier-syntax">id</span><span class="plain-syntax"> = </span><a href="6-rls.html#SP9" class="function-link"><span class="function-syntax">Rules::get_imperative_definition</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">br</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">rule_being_booked</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">id</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">current_sentence</span><span class="plain-syntax"> = </span><span class="identifier-syntax">id</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">at</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">id_body</span><span class="plain-syntax"> *</span><span class="identifier-syntax">idb</span><span class="plain-syntax"> = </span><span class="identifier-syntax">id</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">body_of_defn</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">rulebook</span><span class="plain-syntax"> *</span><span class="identifier-syntax">original_owner</span><span class="plain-syntax"> = </span><a href="5-rf.html#SP17" class="function-link"><span class="function-syntax">RuleFamily::get_rulebook</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">idb</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">head_of_defn</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">placement</span><span class="plain-syntax"> = </span><a href="5-rf.html#SP17" class="function-link"><span class="function-syntax">RuleFamily::get_rulebook_placement</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">idb</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">head_of_defn</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">rulebook</span><span class="plain-syntax"> *</span><span class="identifier-syntax">owner</span><span class="plain-syntax"> = </span><span class="identifier-syntax">original_owner</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">PluginCalls::place_rule</span><span class="plain-syntax">(</span><span class="identifier-syntax">br</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">rule_being_booked</span><span class="plain-syntax">, </span><span class="identifier-syntax">original_owner</span><span class="plain-syntax">, &amp;</span><span class="identifier-syntax">owner</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">owner</span><span class="plain-syntax"> != </span><span class="identifier-syntax">original_owner</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">                    </span><a href="5-rf.html#SP17" class="function-link"><span class="function-syntax">RuleFamily::set_rulebook</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">idb</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">head_of_defn</span><span class="plain-syntax">, </span><span class="identifier-syntax">owner</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                    </span><span class="identifier-syntax">LOGIF</span><span class="plain-syntax">(</span><span class="identifier-syntax">RULE_ATTACHMENTS</span><span class="plain-syntax">, </span><span class="string-syntax">"Rerouting $b: $K --&gt; $K\n"</span><span class="plain-syntax">,</span>
<span class="plain-syntax">                        </span><span class="identifier-syntax">br</span><span class="plain-syntax">, </span><span class="identifier-syntax">original_owner</span><span class="plain-syntax">, </span><span class="identifier-syntax">owner</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                }</span>
<span class="plain-syntax">                </span><a href="6-rlb.html#SP17" class="function-link"><span class="function-syntax">Rulebooks::attach_rule</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">owner</span><span class="plain-syntax">, </span><span class="identifier-syntax">br</span><span class="plain-syntax">, </span><span class="identifier-syntax">placement</span><span class="plain-syntax">, </span><span class="constant-syntax">0</span><span class="plain-syntax">, </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                </span><a href="6-rls.html#SP7" class="function-link"><span class="function-syntax">Rules::set_kind_from</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">br</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">rule_being_booked</span><span class="plain-syntax">, </span><span class="identifier-syntax">owner</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">internal_error</span><span class="plain-syntax">(</span><span class="string-syntax">"Inter-defined rules cannot be automatically placed"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            }</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP7" class="paragraph-anchor"></a><b>&#167;7. Specificity of bookings.</b>This <span class="extract"><span class="extract-syntax">strcmp</span></span>-like function is intended to be used in sorting algorithms,
and returns 1 if <span class="extract"><span class="extract-syntax">br1</span></span> is more specific than <span class="extract"><span class="extract-syntax">br2</span></span>, -1 if <span class="extract"><span class="extract-syntax">br2</span></span> is more specific
than <span class="extract"><span class="extract-syntax">br1</span></span>, or 0 if they are equally good.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="function-syntax">RuleBookings::cmp</span><button class="popup" onclick="togglePopup('usagePopup5')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup5">Usage of <span class="code-font"><span class="function-syntax">RuleBookings::cmp</span></span>:<br/><a href="6-rb.html#SP8_2">&#167;8.2</a><br/>Booking Lists - <a href="6-bl.html#SP5_8_3">&#167;5.8.3</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">booking</span><span class="plain-syntax"> *</span><span class="identifier-syntax">br1</span><span class="plain-syntax">, </span><span class="reserved-syntax">booking</span><span class="plain-syntax"> *</span><span class="identifier-syntax">br2</span><span class="plain-syntax">, </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">log_this</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">br1</span><span class="plain-syntax"> == </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">) || (</span><span class="identifier-syntax">br2</span><span class="plain-syntax"> == </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">)) </span><span class="identifier-syntax">internal_error</span><span class="plain-syntax">(</span><span class="string-syntax">"compared null specificity"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">log_this</span><span class="plain-syntax">) </span><span class="identifier-syntax">LOG</span><span class="plain-syntax">(</span><span class="string-syntax">"Comparing specificity of rules:\n(1) $b\n(2) $b\n"</span><span class="plain-syntax">, </span><span class="identifier-syntax">br1</span><span class="plain-syntax">, </span><span class="identifier-syntax">br2</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><a href="6-rls.html#SP14" class="function-link"><span class="function-syntax">Rules::cmp</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">br1</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">rule_being_booked</span><span class="plain-syntax">, </span><span class="identifier-syntax">br2</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">rule_being_booked</span><span class="plain-syntax">, </span><span class="identifier-syntax">log_this</span><span class="plain-syntax">);</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP8" class="paragraph-anchor"></a><b>&#167;8. Commentary.</b>The sorting algorithm for rulebooks is very important, and Inform authors sometimes
need to know why rulebooks come out in a particular order. So each booking includes
a <a href="6-rb.html#SP8" class="internal">booking_commentary</a> which explains how it came to end up where it did. This
is used only for code comments and the index.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">typedef</span><span class="plain-syntax"> </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="reserved-syntax">booking_commentary</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">next_rule_specificity</span><span class="plain-syntax">; </span><span class="comment-syntax"> 1 for more specific than following, 0 equal, -1 less</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="identifier-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="identifier-syntax">tooltip_text</span><span class="plain-syntax">; </span><span class="comment-syntax"> description of reason</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="identifier-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="identifier-syntax">law_applied</span><span class="plain-syntax">; </span><span class="comment-syntax"> name of Law used to sort</span>
<span class="plain-syntax">} </span><span class="reserved-syntax">booking_commentary</span><span class="plain-syntax">;</span>

<span class="reserved-syntax">booking_commentary</span><span class="plain-syntax"> </span><span class="function-syntax">RuleBookings::new_commentary</span><button class="popup" onclick="togglePopup('usagePopup6')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup6">Usage of <span class="code-font"><span class="function-syntax">RuleBookings::new_commentary</span></span>:<br/><a href="6-rb.html#SP3">&#167;3</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">void</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">booking_commentary</span><span class="plain-syntax"> </span><span class="identifier-syntax">bc</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">bc</span><span class="plain-syntax">.</span><span class="element-syntax">next_rule_specificity</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">bc</span><span class="plain-syntax">.</span><span class="element-syntax">tooltip_text</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">bc</span><span class="plain-syntax">.</span><span class="element-syntax">law_applied</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">bc</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>

<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">RuleBookings::comment</span><span class="plain-syntax">(</span><span class="identifier-syntax">OUTPUT_STREAM</span><span class="plain-syntax">, </span><span class="reserved-syntax">booking</span><span class="plain-syntax"> *</span><span class="identifier-syntax">br</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="identifier-syntax">law</span><span class="plain-syntax"> = </span><span class="identifier-syntax">br</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">commentary</span><span class="plain-syntax">.</span><span class="element-syntax">law_applied</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">switch</span><span class="plain-syntax">(</span><span class="identifier-syntax">br</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">commentary</span><span class="plain-syntax">.</span><span class="element-syntax">next_rule_specificity</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">case</span><span class="plain-syntax"> -1: </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">"  &lt;&lt;&lt; %S &lt;&lt;&lt;"</span><span class="plain-syntax">, </span><span class="identifier-syntax">law</span><span class="plain-syntax">); </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="constant-syntax">0</span><span class="plain-syntax">: </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">"  === equally specific with ==="</span><span class="plain-syntax">); </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="constant-syntax">1</span><span class="plain-syntax">: </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">"  &gt;&gt;&gt; %S &gt;&gt;&gt;"</span><span class="plain-syntax">, </span><span class="identifier-syntax">law</span><span class="plain-syntax">); </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">}</span>

<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">RuleBookings::list_judge_ordering</span><span class="plain-syntax">(</span><span class="reserved-syntax">booking_list</span><span class="plain-syntax"> *</span><span class="identifier-syntax">L</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">LOOP_OVER_BOOKINGS</span><span class="plain-syntax">(</span><span class="identifier-syntax">br</span><span class="plain-syntax">, </span><span class="identifier-syntax">L</span><span class="plain-syntax">)</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">br</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">next_booking</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">br</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">placement</span><span class="plain-syntax"> != </span><span class="identifier-syntax">br</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">next_booking</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">placement</span><span class="plain-syntax">)</span>
<span class="plain-syntax">                </span><span class="named-paragraph-container code-font"><a href="6-rb.html#SP8_1" class="named-paragraph-link"><span class="named-paragraph">Calculate specificities when placements differ</span><span class="named-paragraph-number">8.1</span></a></span>
<span class="plain-syntax">            </span><span class="reserved-syntax">else</span>
<span class="plain-syntax">                </span><span class="named-paragraph-container code-font"><a href="6-rb.html#SP8_2" class="named-paragraph-link"><span class="named-paragraph">Calculate specificities when placements are the same</span><span class="named-paragraph-number">8.2</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">        } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">br</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">commentary</span><span class="plain-syntax">.</span><span class="element-syntax">next_rule_specificity</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">br</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">commentary</span><span class="plain-syntax">.</span><span class="element-syntax">tooltip_text</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">}</span>
</pre>
<ul class="endnotetexts"><li>The structure booking_commentary is private to this section.</li></ul>
<p class="commentary firstcommentary"><a id="SP8_1" class="paragraph-anchor"></a><b>&#167;8.1. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Calculate specificities when placements differ</span><span class="named-paragraph-number">8.1</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="identifier-syntax">br</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">commentary</span><span class="plain-syntax">.</span><span class="element-syntax">next_rule_specificity</span><span class="plain-syntax"> = </span><span class="constant-syntax">1</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">switch</span><span class="plain-syntax">(</span><span class="identifier-syntax">br</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">placement</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">VERY_FIRST_PLACEMENT:</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">br</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">commentary</span><span class="plain-syntax">.</span><span class="element-syntax">tooltip_text</span><span class="plain-syntax"> =</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">I</span><span class="string-syntax">"the rule above was listed as 'very first' so it precedes everything"</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">FIRST_PLACEMENT:</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">switch</span><span class="plain-syntax">(</span><span class="identifier-syntax">br</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">next_booking</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">placement</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">MIDDLE_PLACEMENT:</span>
<span class="plain-syntax">                    </span><span class="identifier-syntax">br</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">commentary</span><span class="plain-syntax">.</span><span class="element-syntax">tooltip_text</span><span class="plain-syntax"> =</span>
<span class="plain-syntax">                        </span><span class="identifier-syntax">I</span><span class="string-syntax">"the rule above was listed as 'first' so precedes this one, which wasn't"</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                    </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">LAST_PLACEMENT:</span>
<span class="plain-syntax">                    </span><span class="identifier-syntax">br</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">commentary</span><span class="plain-syntax">.</span><span class="element-syntax">tooltip_text</span><span class="plain-syntax"> =</span>
<span class="plain-syntax">                        </span><span class="identifier-syntax">I</span><span class="string-syntax">"the rule above was listed as 'first' so precedes this one, listed as 'last'"</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                    </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">VERY_LAST_PLACEMENT:</span>
<span class="plain-syntax">                    </span><span class="identifier-syntax">br</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">commentary</span><span class="plain-syntax">.</span><span class="element-syntax">tooltip_text</span><span class="plain-syntax"> =</span>
<span class="plain-syntax">                        </span><span class="identifier-syntax">I</span><span class="string-syntax">"the rule below was listed as 'very last' so it comes after everything"</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                    </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">default:</span>
<span class="plain-syntax">                    </span><a href="6-bl.html#SP3" class="function-link"><span class="function-syntax">BookingLists::log</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">L</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                    </span><span class="identifier-syntax">internal_error</span><span class="plain-syntax">(</span><span class="string-syntax">"booking list invariant broken"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                    </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            }</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">MIDDLE_PLACEMENT:</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">switch</span><span class="plain-syntax">(</span><span class="identifier-syntax">br</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">next_booking</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">placement</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">LAST_PLACEMENT:</span>
<span class="plain-syntax">                    </span><span class="identifier-syntax">br</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">commentary</span><span class="plain-syntax">.</span><span class="element-syntax">tooltip_text</span><span class="plain-syntax"> =</span>
<span class="plain-syntax">                    </span><span class="identifier-syntax">I</span><span class="string-syntax">"the rule below was listed as 'last' so comes after this one, which wasn't"</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                    </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">VERY_LAST_PLACEMENT:</span>
<span class="plain-syntax">                    </span><span class="identifier-syntax">br</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">commentary</span><span class="plain-syntax">.</span><span class="element-syntax">tooltip_text</span><span class="plain-syntax"> =</span>
<span class="plain-syntax">                        </span><span class="identifier-syntax">I</span><span class="string-syntax">"the rule below was listed as 'very last' so it comes after everything"</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                    </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">default:</span>
<span class="plain-syntax">                    </span><a href="6-bl.html#SP3" class="function-link"><span class="function-syntax">BookingLists::log</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">L</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                    </span><span class="identifier-syntax">internal_error</span><span class="plain-syntax">(</span><span class="string-syntax">"booking list invariant broken"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                    </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            }</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">LAST_PLACEMENT:</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">switch</span><span class="plain-syntax">(</span><span class="identifier-syntax">br</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">next_booking</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">placement</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">VERY_LAST_PLACEMENT:</span>
<span class="plain-syntax">                    </span><span class="identifier-syntax">br</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">commentary</span><span class="plain-syntax">.</span><span class="element-syntax">tooltip_text</span><span class="plain-syntax"> =</span>
<span class="plain-syntax">                        </span><span class="identifier-syntax">I</span><span class="string-syntax">"the rule below was listed as 'very last' so it comes after everything"</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                    </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">default:</span>
<span class="plain-syntax">                    </span><a href="6-bl.html#SP3" class="function-link"><span class="function-syntax">BookingLists::log</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">L</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                    </span><span class="identifier-syntax">internal_error</span><span class="plain-syntax">(</span><span class="string-syntax">"booking list invariant broken"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                    </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            }</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">default:</span>
<span class="plain-syntax">            </span><a href="6-bl.html#SP3" class="function-link"><span class="function-syntax">BookingLists::log</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">L</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">internal_error</span><span class="plain-syntax">(</span><span class="string-syntax">"booking list invariant broken"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="6-rb.html#SP8">&#167;8</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP8_2" class="paragraph-anchor"></a><b>&#167;8.2. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Calculate specificities when placements are the same</span><span class="named-paragraph-number">8.2</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="identifier-syntax">br</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">commentary</span><span class="plain-syntax">.</span><span class="element-syntax">next_rule_specificity</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">switch</span><span class="plain-syntax">(</span><span class="identifier-syntax">br</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">placement</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">VERY_FIRST_PLACEMENT:</span>
<span class="plain-syntax">            </span><a href="6-bl.html#SP3" class="function-link"><span class="function-syntax">BookingLists::log</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">L</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">internal_error</span><span class="plain-syntax">(</span><span class="string-syntax">"multiple very first rules for the same rulebook"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">FIRST_PLACEMENT:</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">br</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">commentary</span><span class="plain-syntax">.</span><span class="element-syntax">tooltip_text</span><span class="plain-syntax"> =</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">I</span><span class="string-syntax">"these rules were both listed as 'first', so they appear in reverse order of listing"</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">MIDDLE_PLACEMENT:</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">br</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">commentary</span><span class="plain-syntax">.</span><span class="element-syntax">next_rule_specificity</span><span class="plain-syntax"> =</span>
<span class="plain-syntax">                </span><a href="6-rb.html#SP7" class="function-link"><span class="function-syntax">RuleBookings::cmp</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">br</span><span class="plain-syntax">, </span><span class="identifier-syntax">br</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">next_booking</span><span class="plain-syntax">, </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">br</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">commentary</span><span class="plain-syntax">.</span><span class="element-syntax">next_rule_specificity</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="identifier-syntax">br</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">commentary</span><span class="plain-syntax">.</span><span class="element-syntax">tooltip_text</span><span class="plain-syntax"> =</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">I</span><span class="string-syntax">"these rules are equally ranked"</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">br</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">commentary</span><span class="plain-syntax">.</span><span class="element-syntax">tooltip_text</span><span class="plain-syntax"> =</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">I</span><span class="string-syntax">"the arrow points from a more specific rule to a more general, as decided by Law"</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">br</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">commentary</span><span class="plain-syntax">.</span><span class="element-syntax">law_applied</span><span class="plain-syntax"> = </span><span class="identifier-syntax">Specifications::law_applied</span><span class="plain-syntax">();</span>
<span class="plain-syntax">            }</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">LAST_PLACEMENT:</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">br</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">commentary</span><span class="plain-syntax">.</span><span class="element-syntax">tooltip_text</span><span class="plain-syntax"> =</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">I</span><span class="string-syntax">"these rules were both listed as 'last', so they appear in order of listing"</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">VERY_LAST_PLACEMENT:</span>
<span class="plain-syntax">            </span><a href="6-bl.html#SP3" class="function-link"><span class="function-syntax">BookingLists::log</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">L</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">internal_error</span><span class="plain-syntax">(</span><span class="string-syntax">"multiple very last rules for the same rulebook"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="6-rb.html#SP8">&#167;8</a>.</li></ul>
<nav role="progress"><div class="progresscontainer">
    <ul class="progressbar"><li class="progressprev"><a href="6-rls.html">&#10094;</a></li><li class="progresschapter"><a href="P-wtmd.html">P</a></li><li class="progresschapter"><a href="1-am.html">1</a></li><li class="progresschapter"><a href="2-bv.html">2</a></li><li class="progresschapter"><a href="3-dlr.html">3</a></li><li class="progresschapter"><a href="4-nr.html">4</a></li><li class="progresschapter"><a href="5-id.html">5</a></li><li class="progresscurrentchapter">6</li><li class="progresssection"><a href="6-rls.html">rls</a></li><li class="progresscurrent">rb</li><li class="progresssection"><a href="6-bl.html">bl</a></li><li class="progresssection"><a href="6-rlb.html">rlb</a></li><li class="progresssection"><a href="6-fao.html">fao</a></li><li class="progresssection"><a href="6-act.html">act</a></li><li class="progresssection"><a href="6-sv.html">sv</a></li><li class="progresschapter"><a href="7-tc.html">7</a></li><li class="progresschapter"><a href="8-kpr.html">8</a></li><li class="progressnext"><a href="6-bl.html">&#10095;</a></li></ul></div>
</nav><!-- End of weave -->

		</main>
	</body>
</html>

